package pos.domain;

import java.util.List;

import pos.data.JDBCEntityDAO;
import pos.data.JDBCEventDAO;

public class EventStore {

	@SuppressWarnings("unused")
	private List<Event> events;
	private static EventStore eventStore;
	
	public static synchronized EventStore getInstance() {
		eventStore = new EventStore();
		
		return eventStore;
	}
	public EventStore() {
		events = (new JDBCEventDAO()).getAllEvents();
	}
	
	public List<Event> getEvents(){
		//return events;
		return (new JDBCEventDAO()).getAllEvents();
	}
	
	public Event getEvent(String idEvent){
		return (new JDBCEventDAO()).getEventById(idEvent);
	}
	
	public Event getEventByTitle(String title){
		return (new JDBCEventDAO()).getEventByTitle(title);
	}
	
	public Event insertEvent(Event event, Category category, Discipline discipline){
		Event eRes = null;
		eRes = new JDBCEventDAO().insertEvent(event,category.getId(),discipline.getId());
		return eRes;
	}
	
	public void removeEntity(Entity entity){
		// didn't remove the associations with (e.g.) Relation because the objective is to have data
		// Would be easy to implement it, if necessary with "Cascade FK" in DB or putting here call to remove method.
		new JDBCEntityDAO().removeEntity(entity);
	}
	
	public boolean existEvent(Event event){
		return new JDBCEventDAO().existEvent(event.getTitle());
	}
}
